package com.sync.utils.project.demo;

import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * TODO
 *
 * @Author YWF
 * @Date 2023/6/19 9:05
 */
@Slf4j
public class MyThread implements Runnable {

    private int i;
    public MyThread(int i) {
        this.i = i;
    }

    private final static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");

    @Override
    public void run() {
        try {
            String threadName = Thread.currentThread().getName();
            log.info("{}-->{} 开始执行...time {}", i,threadName,format.format(new Date()));
            Thread.sleep(10000);
            log.info("{}-->{} 执行结束...time {}", i,threadName,format.format(new Date()));
            i ++;

        } catch (Exception e) {
            log.error("定时任务执行出错");
        }
        if (i == 10){
            throw new RuntimeException();
        }
    }
}
